博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Web功能之组织结构图
阅读量:6363 次
发布时间:2019-06-23

本文共 8184 字,大约阅读时间需要 27 分钟。

    前提:由于项目需要显示组织结构图的形式 

    工具:VS2010 

    项目:ASP.NET 自带的web项目 (带模板页)

    插件:OrgChart(依赖:OrgChart.dll)、JOrgChart

    不多说 先看效果

    1、OrgChart实现效果

    

 

    2、JOrgChart效果

    

    基础实体类代码:

public class SysUserModel : OrgNode    {        public int SysUserId { get; set; }        public string SysUserName { get; set; }        public int SysUserParentId { get; set; }        public override string OrgNodeHtml()        {            this.SysUserName = this.Text;            string str = "
"; //str += "
"; str += "
"; //str += "
"; str += "
";//" + this.SysUserGroupId + " str += "
"; // str += "
"; //str += "
"; str += "
 " + this.SysUserGroupId + "
 
 " + this.SysUserName + "
 
 
"; str += "
"; return str; } }
View Code

    1、OrgChart前台实现代码: 

<%@ Page Title="OrgChart" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %><%@ Register Assembly="OrgChart" Namespace="OrgCharDesigner" TagPrefix="cc1" %>
View Code

        OrgChart后台实现代码:

SysUserModel sysUserModel = new SysUserModel();        DataTable dt;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                ListBind();            }        }               protected void ListBind()        {            try            {                dt = dtList();                SysUserModel root = new SysUserModel();                root.SysUserId = 1;                root.Text = "CEO";                root.SysUserParentId = 0;                SetNodeChild(dt, root);                OrgChart1.Node = root;            }            catch (Exception ex)            {                throw ex;            }        }        private void SetNodeChild(DataTable dt, SysUserModel root)        {            DataRow[] rows = dt.Select(" SysUserParentId = '" + root.SysUserId + "'");// 选出所有子节点            foreach (DataRow drChild in rows)            {                SysUserModel node = new SysUserModel();                node.Text = drChild["SysUserName"].ToString();                node.SysUserId = int.Parse(drChild["SysUserId"].ToString());                node.SysUserParentId = int.Parse(drChild["SysUserParentId"].ToString());                SetNodeChild(dt, node);                root.Nodes.Add(node);            }        }        private DataTable dtList()        {            DataTable dt = new DataTable();            dt.Columns.Add("SysUserId");            dt.Columns.Add("SysUserName");            dt.Columns.Add("SysUserParentId");            dt.Rows.Add();            dt.Rows[0]["SysUserId"] = "1";            dt.Rows[0]["SysUserName"] = "CEO";            dt.Rows[0]["SysUserParentId"] = "0";            dt.Rows.Add();            dt.Rows[1]["SysUserId"] = "2";            dt.Rows[1]["SysUserName"] = "总经理";            dt.Rows[1]["SysUserParentId"] = "1";            dt.Rows.Add();            dt.Rows[2]["SysUserId"] = "3";            dt.Rows[2]["SysUserName"] = "副总经理";            dt.Rows[2]["SysUserParentId"] = "2";            dt.Rows.Add();            dt.Rows[3]["SysUserId"] = "4";            dt.Rows[3]["SysUserName"] = "项目一组";            dt.Rows[3]["SysUserParentId"] = "3";            dt.Rows.Add();            dt.Rows[4]["SysUserId"] = "5";            dt.Rows[4]["SysUserName"] = "项目二组";            dt.Rows[4]["SysUserParentId"] = "3";            dt.Rows.Add();            dt.Rows[5]["SysUserId"] = "6";            dt.Rows[5]["SysUserName"] = "运营总经理";            dt.Rows[5]["SysUserParentId"] = "1";            dt.Rows.Add();            dt.Rows[6]["SysUserId"] = "7";            dt.Rows[6]["SysUserName"] = "运营副总经理";            dt.Rows[6]["SysUserParentId"] = "6";            dt.Rows.Add();            dt.Rows[7]["SysUserId"] = "8";            dt.Rows[7]["SysUserName"] = "运营一组";            dt.Rows[7]["SysUserParentId"] = "7";            dt.Rows.Add();            dt.Rows[8]["SysUserId"] = "9";            dt.Rows[8]["SysUserName"] = "运营二组";            dt.Rows[8]["SysUserParentId"] = "7";            return dt;        }
View Code

    2、JOrgChart 前台实现代码:

<%@ Page Title="jOrgChart" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"    CodeBehind="About.aspx.cs" Inherits="WebApplication1.About" %>    
<%=html%>
View Code

         JOrgChart 后台实现代码:

StringBuilder str = new StringBuilder();        DataTable dt;        protected string html;        protected void Page_Load(object sender, EventArgs e)        {            if (!IsPostBack)            {                html = ListBind();            }        }        protected string ListBind()        {            try            {                dt = dtList();                SysUserModel root = new SysUserModel();                str.Append(" 
  • CEO "); root.SysUserId = 1; root.Text = "CEO"; root.SysUserParentId = 0; SetNodeChild(dt, root); str.AppendLine("
"); return str.ToString(); } catch (Exception ex) { throw ex; } } private void SetNodeChild(DataTable dt, SysUserModel root) { DataRow[] rows = dt.Select(" SysUserParentId = '" + root.SysUserId + "'");// 选出所有子节点 if (rows.Length > 0) { str.Append("
    "); foreach (DataRow drChild in rows) { str.AppendFormat("
  • {1}", drChild["SysUserId"].ToString(), drChild["SysUserName"].ToString()); SysUserModel node = new SysUserModel(); node.Text = drChild["SysUserName"].ToString(); node.SysUserId = int.Parse(drChild["SysUserId"].ToString()); node.SysUserParentId = int.Parse(drChild["SysUserParentId"].ToString()); SetNodeChild(dt, node); str.Append("
  • "); } str.Append("
"); } } private DataTable dtList() { DataTable dt = new DataTable(); dt.Columns.Add("SysUserId"); dt.Columns.Add("SysUserName"); dt.Columns.Add("SysUserParentId"); dt.Rows.Add(); dt.Rows[0]["SysUserId"] = "1"; dt.Rows[0]["SysUserName"] = "CEO"; dt.Rows[0]["SysUserParentId"] = "0"; dt.Rows.Add(); dt.Rows[1]["SysUserId"] = "2"; dt.Rows[1]["SysUserName"] = "总经理"; dt.Rows[1]["SysUserParentId"] = "1"; dt.Rows.Add(); dt.Rows[2]["SysUserId"] = "3"; dt.Rows[2]["SysUserName"] = "副总经理"; dt.Rows[2]["SysUserParentId"] = "2"; dt.Rows.Add(); dt.Rows[3]["SysUserId"] = "4"; dt.Rows[3]["SysUserName"] = "项目一组"; dt.Rows[3]["SysUserParentId"] = "3"; dt.Rows.Add(); dt.Rows[4]["SysUserId"] = "5"; dt.Rows[4]["SysUserName"] = "项目二组"; dt.Rows[4]["SysUserParentId"] = "3"; dt.Rows.Add(); dt.Rows[5]["SysUserId"] = "6"; dt.Rows[5]["SysUserName"] = "运营总经理"; dt.Rows[5]["SysUserParentId"] = "1"; dt.Rows.Add(); dt.Rows[6]["SysUserId"] = "7"; dt.Rows[6]["SysUserName"] = "运营副总经理"; dt.Rows[6]["SysUserParentId"] = "6"; dt.Rows.Add(); dt.Rows[7]["SysUserId"] = "8"; dt.Rows[7]["SysUserName"] = "运营一组"; dt.Rows[7]["SysUserParentId"] = "7"; dt.Rows.Add(); dt.Rows[8]["SysUserId"] = "9"; dt.Rows[8]["SysUserName"] = "运营二组"; dt.Rows[8]["SysUserParentId"] = "7"; return dt; }
View Code

 

以上是本人对于组织结构图的总结 如有好的建议 请您留下  以便新手学习 利人利自!

项目下载地址:

 

转载于:https://www.cnblogs.com/yhyjy/p/3889858.html

你可能感兴趣的文章
图片相似度计算:深入理解DCT变换以及感知哈希
查看>>
Micronaut for Spring支持Spring Boot应用以Micronaut形式运行
查看>>
斯坦福开源Python库StanfordNLP,可处理53种人类语言
查看>>
GitHub采用了新的GraphQL API
查看>>
如何使用package.json文件
查看>>
Microsoft发布模块化区块链服务:Project Bletchley
查看>>
C2x将成为C语言的下一个ISO标准
查看>>
与专门团队一起持续交付
查看>>
Google提出Grasp2Vec模型:利用自监督方法学习物体表示
查看>>
使用TensorFlow的递归神经网络(LSTM)进行序列预测
查看>>
企业金融云存储建设之路
查看>>
新技能Get:如何利用HTTP技术提升网页的加载速度
查看>>
React 0.14候选版发布,添加包分割,Refs语法等新特性
查看>>
php如何实现基于事件驱动的网络编程
查看>>
Memcached 基础笔记
查看>>
[Leetcode] Inorder Successor in BST 二叉搜索树中序遍历找后继
查看>>
php设计模式之实现单例模式(singleton)
查看>>
[LintCode] Largest Rectangle in Histogram
查看>>
DevSecOps 简介(一)
查看>>
理解JS构造函数继承
查看>>